<!DOCTYPE html>
<html>
<head>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no"/>
    <meta charset="UTF-8">
    <title>修改LiDAR</title>
    {% include 'template/baseCss.volt' %}
    <link href="/css/vendor/add-drone.less" rel="stylesheet/less" type="text/css">
    <script src="/js/less.min.js"></script>
</head>
<body>
<main>
    <form>
        <div class="title-bar">
            <label class="server-id">修改LiDAR</label>
        </div>
        <div id="info-wrap">
            <table>
                <tr>
                    <th>LiDAR设备编号: </th>
                    <td>
                        <input type="text" value="{{ lidar['lidar_id'] }}" id="lidar_id">
		            	<input type="hidden" value="{{ lidar['id'] }}" id="id"/>
                    </td>
                </tr>
                <tr>
                    <th>激光扫描仪类型: </th>
                    <td>
                        <select id="laserScannerType_id">
                            <option value="">请选择</option>
                            {% for id,name in laserScannerList %}
                                <option value="{{ id }}" {% if lidar['laserScannerType_id'] ==  id %}  selected = "selected"} {% endif %} >{{ name }}</option>
                            {% endfor %}
                        </select>
                        <label id="add-laser-type-btn" style="cursor:pointer; font-size: 1.5rem; color: #009bff">添加分类</label>
                    </td>
                </tr>
                <tr>
                    <th>激光扫描仪设备ID: </th>
                    <td>
                        <input type="text" value="{{ lidar['laser_scanner_id'] }}" id="laser_scanner_id">
                    </td>
                </tr>
                <tr>
                    <th>IMU类型: </th>
                    <td>
                        <select id="IMUType_id">
                            <option value="">请选择</option>
                            {% for id,name in IMUTypeList %}
                                <option value="{{ id }}" {% if lidar['IMUType_id'] ==  id %}  selected = "selected"} {% endif %} >{{ name }}</option>
                            {% endfor %}
                        </select>
                        <label id="add-IMU-type-btn" style="cursor:pointer; font-size: 1.5rem; color: #009bff">添加分类</label>
                    </td>
                </tr>
                <tr>
                    <th>IMU设备ID: </th>
                    <td>
                        <input type="text" value="{{ lidar['imu_type_id'] }}" id="imu_type_id">
                    </td>
                </tr>
                <tr>
                    <th>检校结果:</th>
		            <td>{{ lidar['check_result_url'] }}</td>
		        </tr>
		        <tr>
		        	<th></th>
                    <td>
                        <input id="upload-result" type="file">
                        <input type="hidden" value="{{ lidar['check_result_url'] }}" name="check_result_url" id="check_result_url"/>
                    </td>
                </tr>
                <tr>
                    <th>检校工程:</th>
		            <td>{{ lidar['check_project_url'] }}</td>
		        </tr>
		        <tr>
		        	<th></th>
                    <td>
                        <input id="upload-project" type="file">
                        <input type="hidden" value="{{ lidar['check_project_url'] }}" name="check_project_url" id="check_project_url"/>
                    </td>
                </tr>
		        <tr>
		            <th>检校结果是否合格:</th>
		            <td><input type="checkbox" value="1" id="qualified" {% if lidar['qualified'] == 1 %}  checked="checked"} {% endif %}/></td>
		        </tr>
            </table>
        </div>
        <p id="save-btn" class="button" style="visibility: visible">修改</p>
        <p id="reset-btn" class="button" style="visibility: visible">重置</p>
    </form>
    <div class="list-box" style="display: none">
        <div class="box-title">
            <label>添加分类</label>
            {#<label class="close-btn">close</label>#}
            <img src="/images/info_edit_del.png" class="close-btn">
        </div>
        <div class="box-list">
            <table class="box-table" cellpadding="0" cellspacing="0">

            </table>
        </div>
        <div class="box-bottom-btn">
            <p class="button" onclick="listBox.clickBoxAdd(this)">添加</p>
            <p class="button" onclick="listBox.clickBoxDel()">删除</p>
        </div>
    </div>
</main>
</body>

{% include 'template/baseJs.volt' %}
<script type="text/javascript" src="/third-part/wang-editor/wangEditor.min.js"></script>
<script src="/js/cos-js-sdk-v5.js"></script>
<script src="/js/vendor/upload-cos.js"></script>

<script>

    var editor = undefined;

    $(function () {
        var E = window.wangEditor;
        editor = new E('#content');
        editor.customConfig.zIndex = 100;
        editor.create();
        CosUpload.cosInit("/file/getCosInfo");
        CosUpload.path = CosUpload.path + "lidar/";
    });

    $("#reset-btn").click(function (){
        location.reload();
    });

    $("#save-btn").click(function () {
        
    	var qualified = 0;
    	if($("#qualified").is(":checked")){//选中  
    		qualified = $("#qualified").val();//打印选中的值  
    	}

        CosUpload.path = CosUpload.path + "lidar/";
        
        var file = $("#upload-result")[0].files[0];
    	if (file) {
        	CosUpload.sliceUpload(file, file.name, "lidar", function (res) {
                if (res.status === 0) {
                    console.log("上传成功");
                    $("#check_result_url").val(res.url);
                    
                    var file = $("#upload-project")[0].files[0];
                    if (file) {
                        loadingProgressView.show();
                        CosUpload.sliceUpload(file, file.name, "lidar", function (res) {
                            if (res.status === 0) {
                                console.log("上传成功");
                                $("#check_project_url").val(res.url);  
                                var data = {
                                    "action_key": REQUEST_ACTION_UPDATE,
                                    "id": $("#id").val(),
                                    "lidar_id": $("#lidar_id").val(),
                                    "laserScannerType_id": $("#laserScannerType_id").val(),
                                    "laser_scanner_id": $("#laser_scanner_id").val(),
                                    "IMUType_id": $("#IMUType_id").val(),
                                    "imu_type_id": $("#imu_type_id").val(),
                                    "check_result_url": $("#check_result_url").val(),
                                    "check_project_url": $("#check_project_url").val(),
                                    "qualified": qualified,
                                    "html": editor.txt.html()
                                };
                                feimaPost("/lidar/editLiDAR", data, function(result){
                                    if (result.status == 0){
                                        loadingProgressView.remove();
                                        window.location.href = "/lidar/listLiDAR";
                                    }else {
                                        loadingProgressView.remove();
                                        FAlert(result.message);
                                    }
                                });              
                            }else {
                                loadingProgressView.remove();
                                FAlert("上传文件失败: " + res.error);
                            }
                        }, function (progress) {
                            console.log(progress);
                            loadingProgressView.setProgress(progress * 0.8 + 0.2);
                        });
                    }else{
                        var data = {
                           "action_key": REQUEST_ACTION_UPDATE,
                           "id": $("#id").val(),
                           "lidar_id": $("#lidar_id").val(),
                           "laserScannerType_id": $("#laserScannerType_id").val(),
                           "laser_scanner_id": $("#laser_scanner_id").val(),
                           "IMUType_id": $("#IMUType_id").val(),
                           "imu_type_id": $("#imu_type_id").val(),
                           "check_result_url": $("#check_result_url").val(),
                           "check_project_url": $("#check_project_url").val(),
                           "qualified": qualified,
                           "html": editor.txt.html()
                       };
                       feimaPost("/lidar/editLiDAR", data, function(result){
                           if (result.status == 0){
                               loadingProgressView.remove();
                               window.location.href = "/lidar/listLiDAR";
                           }else {
                               loadingProgressView.remove();
                               FAlert(result.message);
                           }
                       });
                    }
                }else {
                    FAlert("上传文件失败: " + res.error);
                }
            }, function (progress) {
                console.log(progress);
            });
        }else{
        	var file = $("#upload-project")[0].files[0];
            if (file) {
                loadingProgressView.show();
                CosUpload.sliceUpload(file, file.name, "lidar", function (res) {
                    if (res.status === 0) {
                        console.log("上传成功");
                        $("#check_project_url").val(res.url);  
                        var data = {
                            "action_key": REQUEST_ACTION_UPDATE,
                            "id": $("#id").val(),
                            "lidar_id": $("#lidar_id").val(),
                            "laserScannerType_id": $("#laserScannerType_id").val(),
                            "laser_scanner_id": $("#laser_scanner_id").val(),
                            "IMUType_id": $("#IMUType_id").val(),
                            "imu_type_id": $("#imu_type_id").val(),
                            "check_result_url": $("#check_result_url").val(),
                            "check_project_url": $("#check_project_url").val(),
                            "qualified": qualified,
                            "html": editor.txt.html()
                        };
                        feimaPost("/lidar/editLiDAR", data, function(result){
                            if (result.status == 0){
                                loadingProgressView.remove();
                                window.location.href = "/lidar/listLiDAR";
                            }else {
                                loadingProgressView.remove();
                                FAlert(result.message);
                            }
                        });              
                    }else {
                        loadingProgressView.remove();
                        FAlert("上传文件失败: " + res.error);
                    }
                }, function (progress) {
                    console.log(progress);
                    loadingProgressView.setProgress(progress * 0.8 + 0.2);
                });
            }else{
            	var data = {
                    "action_key": REQUEST_ACTION_UPDATE,
                    "id": $("#id").val(),
                    "lidar_id": $("#lidar_id").val(),
                    "laserScannerType_id": $("#laserScannerType_id").val(),
                    "laser_scanner_id": $("#laser_scanner_id").val(),
                    "IMUType_id": $("#IMUType_id").val(),
                    "imu_type_id": $("#imu_type_id").val(),
                    "check_result_url": $("#check_result_url").val(),
                    "check_project_url": $("#check_project_url").val(),
                    "qualified": qualified,
                    "html": editor.txt.html()
                };
                feimaPost("/lidar/editLiDAR", data, function(result){
                    if (result.status == 0){
                        loadingProgressView.remove();
                        window.location.href = "/lidar/listLiDAR";
                    }else {
                        loadingProgressView.remove();
                        FAlert(result.message);
                    }
                });
            }
        }
    });

    $("#add-laser-type-btn").click(function () {
        $(".list-box").css("display", "block");
        listBox.config = {
            "head": {"id": "ID", "name":"分类名称"},
            "colwidth": {"id": "100", "name": "250"},
            "url": "/lidar/listLaserScannerType"
        };
        listBox.init();
    });

    $("#add-IMU-type-btn").click(function () {
        $(".list-box").css("display", "block");
        listBox.config = {
            "head": {"id": "ID", "name":"分类名称"},
            "colwidth": {"id": "100", "name": "250"},
            "url": "/lidar/listIMUType"
        };
        listBox.init();
    });
    
    $(".close-btn").click(function () {
        $(".list-box").css("display", "none");
        window.location.href = "/lidar/editLiDAR";
    });

</script>
</html>